﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.DynamicData;
using FinWeb3.DynamicData;

namespace FinWeb3
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            // dynamic data registration
            MetaModel model = new MetaModel();
            model.RegisterContext(typeof(FinWebDBDataContext), new ContextConfiguration() { ScaffoldAllTables = true });
            routes.Add(new DynamicDataRoute("DD/{table}/{action}.aspx")
            {
                Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
                Model = model
            });

            // nvc data registration
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Bills",
                "Bills/{fromdate}/{todate}",
                new { controller = "Home", action = "Bills" }
                );
            
            routes.MapRoute(
                "AddDetail",
                "AddDetail/{fromdate}/{todate}/{id}",
                new { controller = "Home", action = "AddDetail" }
                );

            routes.MapRoute(
                "CashFlowIndex",
                "CashFlow/{fromdate}/{todate}",
                new { controller = "CashFlow", action = "Index" }
                );

            routes.MapRoute(
                "StatementIndex",
                "Statement/{fromdate}/{todate}",
                new { controller = "Statement", action = "Index" }
                );

            routes.MapRoute(
                "Default",
                "{controller}/{action}/{fromdate}/{todate}/{id}",
                new { controller = "Home", action = "Index", id = "", fromdate = "", todate = "" }
            );

            routes.MapRoute(
                "BiggerDefault",
                "{controller}/{action}/{fromdate}/{todate}/{idBill}/{idDetail}"
            );

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}